<template>
	<view class="list">
		<view class="title">
			<view class="back-btn" ></view>
					<view class="k">
						课程列表
					</view>
			</view>
			<!-- 列表区域 -->
			<view class="main" v-for="item in kclist">
				<view class="p">
					<image :src="item.cover" mode=""></image>
				</view>
				<view class="lr">
					<view class="lr1">
						{{item.title}}
					</view>
					<view class="lr2">
						<span class="r2-1">￥{{item.price}}</span>
						<span class="r2-2">￥{{item.t_price}}</span>
					</view>
				</view>
			</view>
		</view>
</template>

<script>
	//下拉刷新插件-mescroll
	// import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	// import api from '@/api/api.js'
	import api from '@/api/api.js'
	export default {
		data() {
			return {
				page: 1,
				kclist: [],
				total: 0,
				limit: 10
			}
		},
		onLoad() {
			this.getkc()
		},
		methods: {
           async getkc() {
				let res = await api.getkclist({
					page: this.page
				})
				console.log(res, "kc")
				// this.kclist=res.data.rows
				this.kclist = [...this.kclist, ...res.data.rows]
				this.total = res.data.count/5
			}
		},
		onPullDownRefresh(){
			//下拉刷新
			this.page = 1
			this.total=0,
			setTimeout(()=>{
				uni.stopPullDownRefresh()
				this.getkc()
			},1000)
			uni.showToast({
				title: "刷新"
			})
		},
		
		onReachBottom(){
			if (this.page>=this.total) {
				console.log("到底了");
				uni.showToast({
					title: "到底啦"
				})
			} else {
				this.page++
				this.getkc()
			}
		}
			
		
	}
</script>

<style lang="scss">
	.list {
		width: 100%;
		height: 100%;
	}

	.title {
		width: 100%;
		height: 100rpx;
		// background-color: aqua;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-left: 30rpx;
		padding-right: 30rpx;

		.k {
			padding-right: 270rpx;
		}
	}

	.main {
		width: 100%;
		height: 200rpx;
		// background-color: plum;
		display: flex;
		justify-content: space-around;
		align-items: center;

		.p {
			width: 300rpx;
			height: 170rpx;
			// background-color: #d39e00;
			margin-left: 20rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.lr {
			flex: 1;
			height: 170rpx;
			display: flex;
			margin-left: 10rpx;
			flex-direction: column;
			justify-content: space-between;

			.lr2 {
				.r2-1 {
					color: red;
				}

				.r2-2 {
					color: darkgray;
					font-size: 15rpx;
				}
			}
		}
	}
</style>
